ARG GO_VERSION=1.14
FROM golang:${GO_VERSION}-alpine AS builder

RUN apk update && apk add alpine-sdk git && rm -rf /var/cache/apk/*

WORKDIR /workspace

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN go build -o ./app ./src/main.go

FROM alpine:latest
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

RUN mkdir -p /workspace
WORKDIR /workspace
COPY --from=builder /workspace/app .
COPY --from=builder /workspace/test.db .

EXPOSE 8080
ENTRYPOINT ["./app"]